package jp.melodroid.no9.webview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.KeyEvent;

public class SampleWebView extends Activity
{
    WebView mWebView;
    String mInitUrl = "http://www.google.co.jp";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

	mWebView = (WebView)findViewById(R.id.webview);
	mWebView.getSettings().setJavaScriptEnabled(true);

	//if below sentence is disabled, 
	//clicking a link result in creating Intent.
	mWebView.setWebViewClient(new WebViewClient());
	//mWebView.setWebViewClient(new SampleWebViewClient());

	mWebView.loadUrl(mInitUrl);
   }

    private class SampleWebViewClient extends WebViewClient {
	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
	    view.loadUrl(url);
	    return true;
	}
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
	if ((keyCode == KeyEvent.KEYCODE_BACK) &&
	    (mWebView.canGoBack()) ) {
	    mWebView.goBack();
	    return true;
	}
	else {
	    return super.onKeyDown(keyCode,event);
	}
    }
}
